home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 60914 / 60914.xpi / chrome / content / select.js < prev    next >
Text File  |  2010-01-20  |  8KB  |  313 lines

  1. 
  2.     var PersonaWindowSelectManager={
  3.  
  4.         setTimeOutId:null,
  5.         highlighteds:[],
  6.         CTRLpressed:false,
  7.         SHIFTpressed:false,
  8.         lastedited:null,
  9.  
  10.         getSiblings:function (passednode) {
  11.  
  12.             var activenode=passednode;
  13.             var siblings=[];
  14.             var parentNode=activenode.parentNode;
  15.             var queriednode=null;
  16.             
  17.             for (var i=0;i<parentNode.childNodes.length;i++) {
  18.  
  19.                 queriednode=parentNode.childNodes[i];
  20.                 if(queriednode!=activenode) {siblings.push(parentNode.childNodes[i]);}
  21.  
  22.             }
  23.  
  24.             return siblings;    
  25.  
  26.         },
  27.         
  28.         changeTotrue:function (event) {
  29.         
  30.             if (event.which == 16) PersonaWindowSelectManager.SHIFTpressed=true;
  31.             if (event.which == 17) PersonaWindowSelectManager.CTRLpressed=true;
  32.  
  33.         },
  34.         
  35.         changeTofalse:function (event) {
  36.  
  37.             if (event.which == 16) PersonaWindowSelectManager.SHIFTpressed=false;
  38.             if (event.which == 17) PersonaWindowSelectManager.CTRLpressed=false;
  39.  
  40.         },
  41.  
  42.         insideselection:function (nodepassed) {
  43.  
  44.             for (var i=0;i<PersonaWindowSelectManager.highlighteds.length;i++) {
  45.  
  46.             if (nodepassed==PersonaWindowSelectManager.highlighteds[i]) return true;
  47.  
  48.             }
  49.  
  50.             return false;
  51.             
  52.         },    
  53.             
  54.         clicklistener:function (event) {
  55.             
  56.             if (event.button==1)  {return};
  57.             
  58.             if((PersonaWindowSelectManager.CTRLpressed==true && event.button==2)||(PersonaWindowSelectManager.SHIFTpressed==true&&event.button==2)) return;
  59.                 
  60.             if(PersonaWindowSelectManager.CTRLpressed==true&&PersonaWindowSelectManager.SHIFTpressed==true) {
  61.             
  62.                 PersonaWindowSelectManager.CTRLpressed=true;
  63.                 PersonaWindowSelectManager.SHIFTpressed=false;
  64.             
  65.             }
  66.             
  67.             var highlighthas;
  68.         
  69.             if(PersonasWindow.updateModeOn==true) {alert(PersonasWindow.retrieveAppropriateAlertText());event.preventDefault();return;};
  70.             
  71.             var intendednode=PersonasWindow.hasClass(event.target,"serdo") ? event.target.previousSibling : event.target;
  72.                     
  73.             PersonasWindow.copystate=false;
  74.             
  75.             PersonasWindow.cutstate=false;
  76.             
  77.             
  78.             if (PersonaWindowSelectManager.highlighteds.length>0){
  79.             
  80.                 if(PersonaWindowSelectManager.highlighteds[0].parentNode.parentNode!=intendednode.parentNode.parentNode){
  81.                     
  82.                     var highlightedsarrray=[];
  83.                 
  84.                     for(var i=0;i<document.getElementsByClassName("highlighted").length;i++){
  85.                     
  86.                         highlightedsarrray.push(document.getElementsByClassName("highlighted")[i]);
  87.                         
  88.                     }
  89.                     
  90.                     for (var i=0;i<highlightedsarrray.length;i++) {
  91.             
  92.                         PersonasWindow.removeClass(highlightedsarrray[i],"highlighted");    
  93.         
  94.                     } 
  95.                     
  96.                     PersonaWindowSelectManager.highlighteds=[];
  97.                 
  98.                 }
  99.             
  100.             }
  101.             
  102.             if (event.button==2)  {
  103.  
  104.                 if(PersonaWindowSelectManager.insideselection(intendednode)) {return;}
  105.                 else {highlighthas=true}
  106.  
  107.             }
  108.             
  109.             else {
  110.                 
  111.                 if (PersonasWindow.hasClass(intendednode,"highlighted")) highlighthas=true;
  112.                 else highlighthas=false;
  113.             
  114.             }
  115.  
  116.             if(PersonaWindowSelectManager.CTRLpressed!=true) {
  117.             
  118.                 var highlightedsarrray2=[];
  119.                 
  120.                 for(var i=0;i<document.getElementsByClassName("highlighted").length;i++){
  121.                 
  122.                     highlightedsarrray2.push(document.getElementsByClassName("highlighted")[i]);
  123.                     
  124.                 }
  125.                 
  126.                 for (var i=0;i<highlightedsarrray2.length;i++) {
  127.         
  128.                     PersonasWindow.removeClass(highlightedsarrray2[i],"highlighted");    
  129.     
  130.                 }
  131.                 
  132.                 PersonaWindowSelectManager.highlighteds=[];
  133.         
  134.             }
  135.             
  136.             else {
  137.             
  138.                 if (highlighthas) PersonasWindow.removeClass(intendednode,"highlighted");
  139.                 else {PersonasWindow.addClass(intendednode,"highlighted");}
  140.                 if(PersonasWindow.hasClass(intendednode,"highlighted")) {PersonaWindowSelectManager.highlighteds.push(intendednode);PersonaWindowSelectManager.lastedited=intendednode;}
  141.                 else {PersonaWindowSelectManager.arraydelete(intendednode);PersonaWindowSelectManager.lastedited=intendednode;}
  142.                 return;
  143.                 
  144.             }
  145.             
  146.             if (PersonaWindowSelectManager.SHIFTpressed==true) {
  147.             
  148.                 var highlightedsarrray3=[];
  149.             
  150.                 for(var i=0;i<document.getElementsByClassName("highlighted").length;i++){
  151.                 
  152.                     highlightedsarrray3.push(document.getElementsByClassName("highlighted")[i]);
  153.                     
  154.                 }
  155.                 
  156.                 for (var i=0;i<highlightedsarrray3.length;i++) {
  157.         
  158.                     PersonasWindow.removeClass(highlightedsarrray3[i],"highlighted");    
  159.     
  160.                 }
  161.                 
  162.                 var parentNode=intendednode.parentNode.parentNode;
  163.                 var targetindex;
  164.                 var lasteditedindex;
  165.                 var direction;
  166.                 var nowindex;
  167.                 
  168.                 for (var i=0;i<parentNode.childNodes.length;i++) {
  169.                 
  170.                     if (intendednode==parentNode.childNodes[i].childNodes[0]) targetindex=i;
  171.                     if (PersonaWindowSelectManager.lastedited==parentNode.childNodes[i].childNodes[0]) lasteditedindex=i;
  172.             
  173.                 }
  174.             
  175.                 if (targetindex>lasteditedindex) {
  176.                 
  177.                     direction="ascending";
  178.                     nowindex=targetindex;
  179.                     PersonaWindowSelectManager.highlighteds=[];
  180.                     
  181.                     while (nowindex>=lasteditedindex){
  182.                     
  183.                         
  184.                         PersonasWindow.addClass(parentNode.childNodes[nowindex].childNodes[0],"highlighted");
  185.                         
  186.                         PersonaWindowSelectManager.highlighteds.push(parentNode.childNodes[nowindex].childNodes[0]);        
  187.                         nowindex--;
  188.  
  189.                         PersonaWindowSelectManager.lastedited=parentNode.childNodes[targetindex].childNodes[0];
  190.                         
  191.                     }
  192.  
  193.                     return;
  194.                     
  195.                 }
  196.  
  197.                 if (targetindex<lasteditedindex) {
  198.                     
  199.                     direction="ascending";
  200.                     nowindex=lasteditedindex;
  201.                     PersonaWindowSelectManager.highlighteds=[];
  202.                     
  203.                     while (targetindex<=nowindex){
  204.                         
  205.                         PersonasWindow.addClass(parentNode.childNodes[nowindex].childNodes[0],"highlighted");
  206.                         
  207.                         PersonaWindowSelectManager.highlighteds.push(parentNode.childNodes[nowindex].childNodes[0]);        
  208.                         nowindex--;
  209.  
  210.                         PersonaWindowSelectManager.lastedited=parentNode.childNodes[targetindex].childNodes[0];
  211.                     
  212.                     }
  213.  
  214.                     return;
  215.                 
  216.                 }
  217.                 
  218.                 if (targetindex==lasteditedindex) {
  219.                 
  220.                     direction="ascending";
  221.                     nowindex=lasteditedindex;
  222.                     PersonaWindowSelectManager.highlighteds=[];
  223.                     
  224.                     while (targetindex<=nowindex){
  225.                         
  226.                         PersonasWindow.addClass(parentNode.childNodes[nowindex].childNodes[0],"highlighted");
  227.                         
  228.                         PersonaWindowSelectManager.highlighteds.push(parentNode.childNodes[nowindex].childNodes[0]);        
  229.                         nowindex--;
  230.  
  231.                         PersonaWindowSelectManager.lastedited=parentNode.childNodes[targetindex].childNodes[0];
  232.                     
  233.                     }
  234.  
  235.                     return;
  236.             
  237.                 }
  238.             
  239.             }
  240.             
  241.             if(!PersonasWindow.hasClass(intendednode,"highlighted")) {
  242.                 
  243.                 PersonasWindow.addClass(intendednode,"highlighted");
  244.                 
  245.                 PersonaWindowSelectManager.highlighteds.push(intendednode);
  246.                 PersonaWindowSelectManager.lastedited=intendednode;
  247.                 
  248.             }
  249.  
  250.         },
  251.  
  252.         arraydelete:function (node) {
  253.  
  254.             highlightedscopy=[];
  255.  
  256.             for (var i=0;i<PersonaWindowSelectManager.highlighteds.length;i++){
  257.  
  258.                 if (PersonaWindowSelectManager.highlighteds[i]!=node) highlightedscopy.push(PersonaWindowSelectManager.highlighteds[i]);
  259.  
  260.             }
  261.  
  262.             PersonaWindowSelectManager.highlighteds=highlightedscopy;
  263.  
  264.         },    
  265.         
  266.         handleDoubleClick:function (event) {
  267.  
  268.             window.clearTimeout(PersonaWindowSelectManager.setTimeOutId);
  269.             
  270.  
  271.         },
  272.         
  273.         returnindex:function  (node) {
  274.  
  275.                 var parentNode=node.parentNode;
  276.                 var targetindex;
  277.                 var lasteditedindex;
  278.  
  279.                 for (var i=0;i<parentNode.childNodes.length;i++) {
  280.  
  281.                     if (node==parentNode.childNodes[i]) return i;
  282.                 
  283.                 }
  284.  
  285.         },
  286.  
  287.         multireturnindex:function  () {
  288.  
  289.             var t="";
  290.  
  291.             for (var i=0;i<PersonaWindowSelectManager.highlighteds.length;i++) {
  292.  
  293.                 node=PersonaWindowSelectManager.highlighteds[i];
  294.                 var parentNode=node.parentNode;
  295.  
  296.                 for (var b=0;b<parentNode.childNodes.length;b++) {
  297.  
  298.                     if (node==parentNode.childNodes[b]) { t+=b+",";}
  299.  
  300.                 }
  301.                 
  302.             }
  303.             
  304.             return t;
  305.             
  306.         }
  307.         
  308.     }    
  309.  
  310.     window.addEventListener("keydown",PersonaWindowSelectManager.changeTotrue,false);
  311.     
  312.     window.addEventListener("keyup",PersonaWindowSelectManager.changeTofalse,false);
  313.